home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13639 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.1 KB

  1. Path: chronicle.mti.sgi.com!news
  2. From: austern@isolde.mti.sgi.com (Matt Austern)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Will JAVA kill C++?
  5. Date: 26 Mar 1996 20:14:27 GMT
  6. Organization: SGI
  7. Message-ID: <AUSTERN.96Mar26121428@isolde.mti.sgi.com>
  8. References: <313E44EA.14D110C0@netcom.com> <4hp18v$3di@frodo.smartlink.net>
  9.     <4ht8k1$t7l@epx.cis.umn.edu> <3146278D.7703E9CC@netcom.com>
  10.     <4i6q13$4e8@gaia.ns.utk.edu> <4j9gf5$e01@druid.borland.com>
  11. Reply-To: austern@mti.sgi.com
  12. NNTP-Posting-Host: isolde.mti.sgi.com
  13. In-reply-to: pete@borland.com's message of 26 Mar 1996 19:27:33 GMT
  14.  
  15. In article <4j9gf5$e01@druid.borland.com> pete@borland.com (Pete Becker) writes:
  16.  
  17. > >If you want to use features of C++ that theoretically ought to seem
  18. > >good for numerical programming, such as complex number classes and 
  19. > >especially matrix classes, various language consequences of C++ combine
  20. > >to make things slower than they should be with nearly all compilers if you
  21. > >want to use idiomatic matrix classes. 
  22. >     It turns out that this isn't necessarily true. There was a paper 
  23. > presented by David Vandevoorde at the latest ANSI/ISO C++ meeting about 
  24. > implementing the valarray template in a way that permitted aggressive 
  25. > optimizations. With his changes, expressions like sum(1.2*x-2.3*y+3.4); can be 
  26. > compiled into code that runs just as fast as the corresponding C code with 
  27. > explicit loops, plus a bit of setup time. That's with straight gcc, not a 
  28. > compiler that's specifically optimized for valarray.
  29.  
  30. David's technique, though, relies on compile-time dispatching: in
  31. essence, using C++ more as a generic language (in the style of the
  32. STL, and of Barton and Nackman's book) than as an object-oriented
  33. language.
  34.  
  35. Matt Kennel's concern is about using OO techniques for numerical
  36. programming: specifically, he's worried that if you declare a function
  37. to be virtual, then the compiler will do the extra work for a virtual
  38. function call even when the object's actual type is (or should be)
  39. known at compile time.  This might cause serious performance problems
  40. in loops, unless you have a compiler that optimizes these things out.
  41. I don't know how common these sorts of optimizations are.
  42.  
  43. In general, though, I have the same feeling about Matt's objection as
  44. in that old joke about the man who tells his physician "Doc, it hurts
  45. when I do this," and gets the response "Well, don't do that."  You
  46. don't have to use OO techniques for numerical programming, you don't
  47. have to declare functions virtual, and, even if you're using someone
  48. else's library where everything is declared virtual, you don't have to
  49. use a form of function calls that implies virtual dispatch.
  50.  
  51. The most important part of my last paragraph is that you don't have to
  52. use OO techniques at all when they're inappropriate: generic
  53. programming is often more useful, especially if you're interested in
  54. performance.  C++'s greatest strength is that it supports both OOP and
  55. generic programming (despite C++'s weaknesses, it has better support
  56. for generic programming than does any other language I've seen) and
  57. that it lets you combine the two techniques.
  58. -- 
  59. Matt Austern
  60. SGI: MTI Compilers Group
  61. austern@isolde.mti.sgi.com
  62.